//
//  MineViewController.m
//  跨界收
//
//  Created by MT on 2018/10/27.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "MineViewController.h"
#import "AccountMenuView.h"
#import "AddBankCardViewController.h"
#import "SettingsViewController.h"
#import "NotificationTwoViewController.h"
#import "AboutUsViewController.h"
#import "ConsumptionFlowViewController.h"
#import "RedPageViewController.h"
#import "CodeBarViewController.h"
#import "MemberViewController.h"
#import "shopMessageViewController.h"
#import "RegisterServerViewController.h"
#import "LYLPhotoTailoringTool.h"
#import "NoticeViewController.h"
#import "ActiveViewController.h"
#import "ShangpinZhanShiViewController.h"
#import "DianPuXinXiViewController.h"
#import "ZhiFuMemberViewController.h"
#import "MyMemberViewController.h"
#import "PutForwardViewController.h"

@interface MineViewController ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *naviewConstraint;
@property (weak, nonatomic) IBOutlet UIView *naviView;
@property (weak, nonatomic) IBOutlet UIImageView *picImageView;
@property (weak, nonatomic) IBOutlet UILabel *shopnameLabel;
@property (weak, nonatomic) IBOutlet UIButton *registerServerBtn;
@property (weak, nonatomic) IBOutlet UIButton *VButton;
@property (weak, nonatomic) IBOutlet UIButton *putForwardBtn;
@property (weak, nonatomic) IBOutlet UILabel *IDLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceContraint;
@property (weak, nonatomic) IBOutlet UIView *moneyView;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *putforwardConstraint;
@property (weak, nonatomic) IBOutlet UILabel *bossLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *putWidthConstarnt;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *putHeightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *regiterConstraint;
@property (nonatomic, strong) AccountMenuView *menuView;

@end

@implementation MineViewController

#pragma mark - Lifecycle
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self createAccountMenuView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPic:)];
    [self.picImageView addGestureRecognizer:tap];
    self.picImageView.userInteractionEnabled = YES;
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    if (WYFIphoneX){
        //获取状态栏的rect
        CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];
        self.naviewConstraint.constant = statusRect.size.height;
    }
    self.putForwardBtn.layer.masksToBounds = YES;
    self.putForwardBtn.layer.cornerRadius = 3.0;
    self.menuView.frame = CGRectMake(0, self.moneyView.y+self.moneyView.height + 15.0, SCREEN_WIDTH, 200.0);
    [self judgeIphone4SLayout];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    
    [self updateUserInfo];
}

#pragma mark - Routine
- (void)updateUserInfo
{
    self.shopnameLabel.text = [UserModel sharedModel].nick_name;
    self.IDLabel.text = [NSString stringWithFormat:@"ID:%@", [UserModel sharedModel].id_];
    self.bossLabel.text = [UserModel sharedModel].title;
    CGFloat money = [UserModel sharedModel].money;
    if (money > 0) {
        self.priceLabel.text = [NSString stringWithFormat:@"%.2f", money];
    }
    [self.picImageView setImageWithURL:[NSURL URLWithString:[UserModel sharedModel].head_img] placeholder:[UIImage imageNamed:@"app_logo"]];
}

- (IBAction)registerServer:(id)sender
{
    RegisterServerViewController *reVC = [[RegisterServerViewController alloc]initWithNibName:@"RegisterServerViewController" bundle:nil];
    reVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:reVC animated:YES];
}

- (void)createAccountMenuView
{
    WeakSelf;
    self.menuView = [[AccountMenuView alloc] init];
    self.menuView.tapItemViewBlock = ^(NSInteger tag) {
        [weakSelf pushViewControlls:tag];
    };
    [self.view addSubview:self.menuView];
}
- (IBAction)putForward:(id)sender {
    
//    if ([self.priceLabel.text floatValue]<50) {
//        [self showInfo:@"金额必须50元以上才能提现！"];
//    }else{
        NSString *token = (NSString *)[Tool getLocalDataValue:kAccessTokenKey];
        NSMutableDictionary *requestDic = [NSMutableDictionary dictionary];
        [requestDic setObject:token forKey:kAccessTokenKey];
        [NetworkManager post:kGetBankCardApi parameters:requestDic success:^(id data) {
            NSLog(@"getBankCard:%@",data);
            NSDictionary *dataDic = (NSDictionary *)data;
            if ([dataDic[@"status"] integerValue]== 3007) {
                AddBankCardViewController *pfVC = [[AddBankCardViewController alloc]initWithNibName:@"AddBankCardViewController" bundle:nil];
                pfVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:pfVC animated:YES];
            }else if ([dataDic[@"status"] integerValue]== 3008){
                PutForwardViewController *putVC = [[PutForwardViewController alloc] initWithNibName:@"PutForwardViewController" bundle:nil];
                putVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:putVC animated:YES];
            }
        } failure:^(NSError *error) {
            [self handleRequestFailure:error];
        }];
//    }
}
- (void)pushViewControlls:(NSInteger)tag
{
    switch (tag) {
        case 1000:
        {
            NSArray *titleArr = @[@"商品展示",@"店铺信息"];
            NSArray *vcArr = @[[ShangpinZhanShiViewController class],[DianPuXinXiViewController class],];
            shopMessageViewController *recordVC = [[shopMessageViewController alloc] initWithViewControllerClasses:vcArr andTheirTitles:titleArr];
            recordVC.menuItemWidth = SCREEN_WIDTH/2.0;
            recordVC.menuViewStyle = WMMenuViewStyleLine;
            recordVC.titleColorNormal = [UIColor whiteColor];
            recordVC.titleColorSelected = [UIColor cz_colorWithHex:0xF6F6F6];
            recordVC.progressWidth = 50.0;
            recordVC.progressHeight = 2.0;
            recordVC.progressColor = [UIColor whiteColor];
            recordVC.hidesBottomBarWhenPushed = YES;
            //            recordVC.showOnNavigationBar = YES;
            [self.navigationController pushViewController:recordVC animated:YES];
        }
            break;
        case 1001:
        {
            NSArray *titleArr = @[@"支付会员",@"我的会员"];
            NSArray *vcArr = @[[MyMemberViewController class],[ZhiFuMemberViewController class],];
            MemberViewController *recordVC = [[MemberViewController alloc] initWithViewControllerClasses:vcArr andTheirTitles:titleArr];
            recordVC.menuItemWidth = SCREEN_WIDTH/2.0;
            recordVC.menuViewStyle = WMMenuViewStyleLine;
            recordVC.titleColorNormal = [UIColor whiteColor];
            recordVC.titleColorSelected = [UIColor cz_colorWithHex:0xF6F6F6];
            recordVC.progressWidth = 50.0;
            recordVC.progressHeight = 2.0;
            recordVC.progressColor = [UIColor whiteColor];
            recordVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:recordVC animated:YES];
            
        }
            break;
        case 1002:
        {
            CodeBarViewController *cVC = [[CodeBarViewController alloc] initWithNibName:@"CodeBarViewController" bundle:nil];
            cVC.hidesBottomBarWhenPushed = YES;
            cVC.naviHidden = YES;
            [self.navigationController pushViewController:cVC animated:YES];
        }
            break;
        case 1003:
        {
            RedPageViewController *rVC = [[RedPageViewController alloc] initWithNibName:@"RedPageViewController" bundle:nil];
            rVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:rVC animated:YES];
        }
            break;
        case 1004:
        {
            ConsumptionFlowViewController *cVC = [[ConsumptionFlowViewController alloc] initWithNibName:@"ConsumptionFlowViewController" bundle:nil];
            cVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:cVC animated:YES];
        }
            break;
        case 1005:
        {
            AboutUsViewController *aVC = [[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];
            aVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:aVC animated:YES];
        }
            break;
        case 1006:
        {
            NSArray *titleArr = @[@"公告",@"活动"];
            NSArray *vcArr = @[[NoticeViewController class],[ActiveViewController class],];
            NotificationTwoViewController *recordVC = [[NotificationTwoViewController alloc] initWithViewControllerClasses:vcArr andTheirTitles:titleArr];
            recordVC.menuItemWidth = SCREEN_WIDTH/2.0;
            recordVC.menuViewStyle = WMMenuViewStyleLine;
            recordVC.titleColorNormal = [UIColor whiteColor];
            recordVC.titleColorSelected = [UIColor cz_colorWithHex:0xF6F6F6];
            recordVC.progressWidth = 50.0;
            recordVC.progressHeight = 2.0;
            recordVC.progressColor = [UIColor whiteColor];
            recordVC.hidesBottomBarWhenPushed = YES;
            //            recordVC.showOnNavigationBar = YES;
            [self.navigationController pushViewController:recordVC animated:YES];
        }
            break;
        case 1007:
        {
            SettingsViewController *settingsVC = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
            settingsVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:settingsVC animated:YES];
        }
            break;
        default:
            break;
    }
}
- (void)judgeIphone4SLayout
{
    if (SCREEN_WIDTH < 375.0) {
        self.putWidthConstarnt.constant = 50;
        self.putHeightConstraint.constant = 30;
        self.priceContraint.constant = 73.0;
        self.regiterConstraint.constant = 80;
        self.registerServerBtn.titleLabel.font = [UIFont systemFontOfSize:10];
        
    }
}

- (void)tapPic:(UITapGestureRecognizer *)tap
{
    WeakSelf;
    [[LYLPhotoTailoringTool sharedTool] photoTailoring:^(UIImage *image) {
        weakSelf.picImageView.image = image;
        
    }];
}
@end
